package com.wqm.batis.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.wqm.batis.common.LongIdParam;
import com.wqm.batis.common.PageVo;
import com.wqm.batis.common.Responses;
import com.wqm.batis.domain.HelloPay;
import com.wqm.batis.service.HelloPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * example表的注释 前端控制器
 *
 * @author: 王钦民
 * @date : 2023-12-18
 * @description: 一起变好吧
 */
@RestController
@RequestMapping("/app/hello-pay")
@Api(tags = "hello_pay-example表的注释-基础功能")
@ApiSupport(author = "王钦民", order = 999)
public class HelloPayController {

    @Resource
    private HelloPayService helloPayService;

    /**
     * 新增
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增", notes = "添加-example表的注释")
    @ApiOperationSupport(author = "王钦民", order = 1, ignoreParameters = {"id", "createTime", "updateTime"})
    public Responses<Long> insertHelloPay(@RequestBody HelloPay entity) {
        helloPayService.save(entity);
        return Responses.ok(entity.getId());
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除", notes = "删除-根绝id删除数据")
    @ApiOperationSupport(author = "王钦民", order = 2)
    public Responses<Boolean> deleteHelloPay(@RequestBody LongIdParam param) {
        boolean flag = helloPayService.removeById(param.getId());
        return Responses.ok(flag);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "修改-根据id修改数据")
    @ApiOperationSupport(author = "王钦民", order = 3, ignoreParameters = {"createTime", "updateTime"})
    public Responses<Boolean> updateHelloPay(@RequestBody HelloPay entity) {
        boolean flag = helloPayService.updateById(entity);
        return Responses.ok(flag);
    }

    /**
     * 修改-带乐观锁
     */
    @PostMapping("/updateOptimisticLock")
    @ApiOperation(value = "修改(乐观锁)", notes = "修改(乐观锁)-根据id修改数据")
    @ApiOperationSupport(author = "王钦民", order = 4, ignoreParameters = {"createTime", "updateTime", "revision"})
    public Responses<Boolean> updateOptimisticLock(@RequestBody HelloPay entity) {
        // 数据库实时查询version字段值
        entity.setRevision(helloPayService.getById(entity.getId()).getRevision());
        boolean flag = helloPayService.updateById(entity);
        return Responses.ok(flag);
    }

    /**
     * 查询
     */
    @PostMapping("/getDetailById")
    @ApiOperation(value = "查询", notes = "查询-根据id查看详情")
    @ApiOperationSupport(author = "王钦民", order = 5)
    public Responses<HelloPay> getDetailById(@RequestBody LongIdParam param) {
        return Responses.ok(helloPayService.getById(param.getId()));
    }

    /**
     * 所有列表
     */
    @PostMapping("/getAllList")
    @ApiOperation(value = "查询所有", notes = "查询所有-查询所有数据")
    @ApiOperationSupport(author = "王钦民", order = 6)
    public Responses<List<HelloPay>> getAllList() {
        List<HelloPay> list = helloPayService.list();
        return Responses.ok(list);
    }

    /**
     * 查询-无条件分页列表
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "查询-无条件分页列表", notes = "查询-无条件分页列表(默认创建时间降序排序)")
    @ApiOperationSupport(author = "王钦民", order = 7)
    public Responses<PageVo<HelloPay>> getPageList(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        PageVo<HelloPay> pageUtils = helloPayService.getPageList(page, pageSize);
        return Responses.ok(pageUtils);
    }

}

